import 'package:xvideos/hj_utils/api_service/acg_service.dart';
import 'package:xvideos/tools_base/base_list_controller.dart';

class CartoonSectionSubLogic extends ListBaseLogic {
  int? sortType;
  String? sectionID;
  int? pageType; //0-动漫 1-漫画
  String? kind;

  CartoonSectionSubLogic({
    this.sortType,
    this.sectionID,
    this.pageType,
    this.kind,
  });

  @override
  void onReady() {
    super.onReady();
    loadData();
  }

  loadData({int page = 1, int size = 12}) async {
    dataList ??= [];
    final resp = await ACGService.getPreferences(
      page,
      size,
      sortType: sortType,
      sId: sectionID ?? '',
      type: 0,
    );

    if (resp != null) {
      currentPage = page;
      if (page == 1) dataList?.clear();
      dataList?.addAll(resp.list ?? []);
    }
    update();
    resp?.hasNext == true ? refreshCtr?.loadComplete() : refreshCtr?.loadNoData();
    refreshCtr?.refreshCompleted();
  }

  loadMoreData() => loadData(page: currentPage + 1);
}
